package com.xyht.sca_s.student_manage_system.modules.attendance.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.annotation.RepeatRequestCheck;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.attendance.entity.req.SmsAttendanceDetailReq;
import com.xyht.sca_s.student_manage_system.modules.attendance.service.SmsAttendanceDetailService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 考勤打卡详情 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2023-02-23
 */
@RestController
@RequestMapping("/attendance/detail")
@SecretBody
public class SmsAttendanceDetailController {
    @Autowired
    private SmsAttendanceDetailService smsAttendanceDetailService;
    @Autowired
    private JwtTokenUtil jwtTokenUtil;


    @ApiModelProperty(value = "学生打卡签到")
    @PostMapping("/sign")
    public ResponseResult studentSignInAttendance(@RequestBody SmsAttendanceDetailReq smsAttendanceDetailReq,HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsAttendanceDetailService.studentSignInAttendance(smsAttendanceDetailReq,user_id);
    }

    @ApiModelProperty(value = "教师打卡异常状态修改")
    @PostMapping("/update")
    @RepeatRequestCheck
    public ResponseResult teacherUpdateAttendanceDetail(@RequestBody SmsAttendanceDetailReq smsAttendanceDetailReq,HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsAttendanceDetailService.teacherUpdateAttendanceDetail(smsAttendanceDetailReq,user_id);
    }

    @ApiModelProperty(value = "学生考勤打卡签到详情")
    @GetMapping("/signDetail")
    public ResponseResult getSignInAttendanceDetail(HttpServletRequest request,
                                              @RequestParam(value = "attendance_id") String attendance_id
    ) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsAttendanceDetailService.getSignInAttendanceDetail(attendance_id,user_id);
    }

    @ApiModelProperty(value = "学生考勤打卡签到列表")
    @GetMapping("/list")
    public ResponseResult getSignInAttendanceList(HttpServletRequest request,
                                            @RequestParam(value = "search_str", required = false) String search_str,
                                            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                            @RequestParam(value = "bg_date", required = false) String bg_date,
                                            @RequestParam(value = "end_date", required = false) String end_date
    ) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsAttendanceDetailService.getSignInAttendanceList(pageNum,pageSize,bg_date,end_date,search_str,user_id);
    }

    @ApiModelProperty(value = "学生考勤打卡签到历史列表")
    @GetMapping("/historyList")
    public ResponseResult getSignInAttendanceHistoryList(HttpServletRequest request,
                                            @RequestParam(value = "search_str", required = false) String search_str,
                                            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                            @RequestParam(value = "bg_date", required = false) String bg_date,
                                            @RequestParam(value = "end_date", required = false) String end_date,
                                            @RequestParam(value = "attendance_status", required = false) Integer attendance_status
    ) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsAttendanceDetailService.getSignInAttendanceHistoryList(pageNum,pageSize,bg_date,end_date,search_str,attendance_status,user_id);
    }

}

